Skip to content

Conversation

@gbrgr
Copy link
Collaborator

@gbrgr gbrgr commented Dec 22, 2025

Implements a custom authenticator for HttpClient and RestCatalog.

@gbrgr gbrgr marked this pull request as ready for review December 22, 2025 10:16
@gbrgr gbrgr requested a review from vustef December 22, 2025 10:17
Copy link

@vustef vustef left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Gerald, I like how this turned out. I just have one minor concern regarding exposing this in RestCatalogBuilder vs RestCatalog

/// Set a custom token authenticator.
///
/// The authenticator will be used to obtain tokens instead of using static tokens
/// or OAuth credentials. This must be called before any catalog operations.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not add this method to the RestCatalogBuilder instead? That way by the time catalog is created, one either provided the token authenticator or not. And maybe we get rid of OnceCell.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment on lines 236 to 242
req.headers_mut().insert(
http::header::AUTHORIZATION,
format!("Bearer {token}").parse().map_err(|e| {
Error::new(ErrorKind::DataInvalid, "Invalid token from authenticator!")
.with_source(e)
})?,
);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is exactly the same as the one below at line 266, except for the error message. Can we avoid duplication? Ideally through control flow, but if not, then by having this as a function

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

// Verify authenticator was called
let count = *call_count.lock().unwrap();
assert!(
count > 0,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we check for exact count? so that not only we verify it was called once, but that it was called multiple times, and therefore refresh will work too.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see actually that's what the next test does. Any reason to have these two as separate tests?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed that one

Copy link

@vustef vustef left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few more, mostly test harness cleanup. But LGTM otherwise

format!("Bearer {token}").parse().map_err(|e| {
Error::new(
ErrorKind::DataInvalid,
"Invalid token received from catalog server!",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should customize the message, as the token has different source depending what is the place of invocation of this function

async fn test_catalog_with_custom_token_authenticator() {
let catalog = get_catalog().await;
async fn test_authenticator_token_refresh() {
set_up();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of duplicating this code, let's reuse get_catalog. Maybe create get_catalog_with_authenticator, that wraps get_catalog. Or have private method that both call.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or some other solution, but we should hide all these details like get_catalog does.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a custom get_catalog method

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to convey that it should reuse code with fn get_catalog though, would that be possible?

@gbrgr gbrgr enabled auto-merge (squash) December 22, 2025 12:16
@gbrgr gbrgr merged commit 3482910 into main Dec 22, 2025
14 checks passed
@gbrgr gbrgr deleted the feature/gb/custom-auth branch December 22, 2025 12:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants